package com.nt.redisdemo.nt.controller;


import com.cebbank.essp.common.service.RedisOpsService;
import com.cebbank.essp.common.service.RedisStringService;
import com.nt.redisdemo.nt.service.EasyExcelService;
import com.nt.redisdemo.nt.service.KeyCompareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("nt")
public class RedisController {

    @Autowired
    KeyCompareService keyCompareService;

    @Autowired
    EasyExcelService easyExcelService;

    @Autowired
    protected RedisOpsService redisService;

    @Autowired
    protected RedisStringService redisStrService;



    /**
     * redis 基础 测试
     * @return
     */
    @RequestMapping("/redisStrtest")
    @ResponseBody
    public String redisStrtest() {
        boolean key1 = redisStrService.hasConfig("group1:1", "key1");
        System.out.println("hasConfig:"+key1);

        redisStrService.setConfig("group1:1", "key1", "value1");
        redisStrService.setConfig("group1:1", "key2", "value2");

        boolean key2 = redisStrService.hasConfig("group1:1", "key1");
        System.out.println("hasConfig:"+key2);


        Map<Object, Object> configGroup = redisStrService.getConfigGroup("group1:1");
        System.out.println("getConfigGroup:"+configGroup);

        redisStrService.deleteConfig("group1:1", "key1");
        System.out.println(redisStrService.hasConfig("group1:1", "key1"));
        System.out.println(redisStrService.getConfig("group1:1", "key1"));


        return "s";
    }



    /**
     * redis 基础 测试
     * @return
     */
    @RequestMapping("/redistest")
    @ResponseBody
    public String redistest() {
        // set方法
        boolean set = redisService.set("redistest", "redistest");
        System.out.println("set方法:"+set);

        String s = redisService.get("redistest");
        System.out.println("get方法"+s);
        return s;
    }



}
